package agents.interaction;

import extra.Position;

import constants.*;
import interfaces.ActionInterface;
import interfaces.impl.HumanInteraction;

import java.awt.Graphics;
import java.util.ArrayList;

import actions.ActionAddEffect;
import agents.effect.EffectMoveRandom;

import objects.WorldObject;
import universe.Universe;

public class InteractionMoveRandom extends HumanInteraction{
	
	private WorldObject objectToMove=null;
	private ActionAddEffect actionAddEffect;
	
	public InteractionMoveRandom(){
		this.id=Constants.AGENT_HUMAN_INTERACTION_MOVE_RANDOM;
		
		listActions= new ArrayList<ActionInterface>();
		
		actionAddEffect= new ActionAddEffect(priority);
		listActions.add(actionAddEffect);
		
		numParameters=0;
		totalParameters=1;
		isActive=false;
	}

	@Override
	public boolean setParameter(String parameter, Universe universe) {
		String str[] = parameter.split("/");
		
		int id = Integer.parseInt(str[2]);
		objectToMove = universe.getObject(id);
		if(objectToMove!=null){
			isActive=true;
			return true;
		}
		
		
		return false;
		
	}
	
	@Override
	public String getParameters() {
		String res= new String();
		res=Constants.PARAMETER_OBJECT+"";
		return res;
		
	}
	@Override
	public void update(WorldObject object, Universe worldI, double time) {

		if(!isActive){
			//System.out.println("No estoy activo");
			return;
		}
		if(!canUpdate(object)){
			System.out.println("Me falta alguna accion para poder actuar");
			return;
		}
		System.out.println("ASIGNE EL EFFECTO");
		actionAddEffect.setEffect(new EffectMoveRandom());
		actionAddEffect.setSource(object);
		actionAddEffect.setTarget(objectToMove);
		
		objectToMove.setImmediatlyActionToDo(actionAddEffect);
		
		
		isActive=false;
		objectToMove=null;
		
	}

	@Override
	public void paint(Graphics g, WorldObject object) {

		
	}

	@Override
	public String getName() {

		return "Move Random";
	}

	
	
	

}
